home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17368 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: pluto.njcc.com!not-for-mail
  2. From: mike@pluto.njcc.com (Michael Hohenshilt)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Calling the wrong constructor
  5. Date: 15 Apr 1996 15:08:31 GMT
  6. Organization: New Jersey Computer Connection, Lawrenceville, NJ
  7. Message-ID: <4ktopf$21s@earth.njcc.com>
  8. References: <4kot87$796@earth.njcc.com> <4kpm4c$jfe@nntp1.best.com> <3170DEB7.66C6@sto.fdata.se>
  9. NNTP-Posting-Host: pluto.njcc.com
  10. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  11.  
  12. Niklas Mellin (niklas.mellin@sto.fdata.se) wrote:
  13. : > The destructors need to be virtual.
  14. : > 
  15. : > virtual ~Foo() { { /* ... */ }
  16. : > virtual ~Parent() { /* ... */ }
  17. : Only Parent has to be expicitly declared virtual, declaring derived
  18. : classes overloaded functions as virtual when they are already declared
  19. : virtual in the base class is optional. A good habit though since it
  20. : might make the code clearer.
  21. : ---
  22. : Niklas Mellin
  23.  
  24.   Thanks for that tip.  I didn't think you could declare a destructor as 
  25. virtual (Okay to be honest, it never occured to me either).  I did solve 
  26. the problem however. Messy, messy, messy technique by adding a new 
  27. virtual function that allows the derived class to destroy itself from the 
  28. base class' destructor (this emulated a destructor).  The worst part about 
  29. it is that I have about 10 derived classes (and still growing) where 
  30. most of them required a custom Destroy function (there own destructors 
  31. became pretty much obsolete afterwards), but I'm going to change it. In 
  32. fact I put my little project aside (well...it's not so little anymore), 
  33. and play around with the language some more by pushing the C++  language 
  34. to it's limits and hopefully get some more insight into the language.
  35.  
  36.         Thanks again
  37.  
  38. : Michael Hohenshilt
  39. : Wisdom is ofttimes nearer when we stoop 
  40. : Than when we soar.
  41.  
  42.